import Ember from 'ember';
import config from 'game-front/config/environment';

export default Ember.Route.extend({
  share:Ember.inject.service(),
  model(params) {
    var share = this.get("share");
    var userInfo = this.modelFor("application");
    var link = window.location.origin + config.baseURL + "sharegrade?"  + Ember.$.param($.extend(params, {key:userInfo.userId}));
    var shareLink = {
      title: '90秒夺宝-PM大逃亡-本次存活' + params.score +'秒', // 分享标题
      desc: `居然存活了${params.score}秒，求超越`,
      link: link + "#public=true", // 分享链接
      imgUrl: 'http://game.inkanke.com/yydb/assets/images/ICON2.png', // 分享图标
      success: function () {
        share.reward(userInfo.userId);
        // 生成推荐二维码
        share.createQR(userInfo.userId);
      },
      cancel: function () {
        // 用户取消分享后执行的回调函数
      }
    };
    share.config(shareLink);

    params.position = parseInt(params.position) + 1;
    return params;
  },
  beforeModel: function(posts, transition) {
    Ember.run.scheduleOnce('afterRender', this, function() {
      $(".ranking").height(document.body.scrollHeight);
    });
  },

  actions: {
    showShare() {
      $(".shade-share").css({"display": "block"});
    },
    hidder(){
      $(".shade-share").css({"display": "none"});
    }
  }
});
